package com.heima.article.lisent;


import com.heima.common.constants.article.HotArticleConstants;
import lombok.extern.slf4j.Slf4j;
import org.checkerframework.checker.units.qual.A;
import org.springframework.amqp.rabbit.annotation.Queue;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.ListOperations;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Component;

@Component
@Slf4j
public class HotArticleScoreListener {

    @Autowired
    private StringRedisTemplate redisTemplate;


    @RabbitListener(queuesToDeclare = @Queue(HotArticleConstants.HOT_ARTICLE_SCORE_BEHAVIOR_QUEUE))
    private void articleBehaviorHandler(String behaviorMess){
        log.info("文章实时更新队列 : 接收到文章行为变化 消息内容{}",behaviorMess);

        //创建redis的存储对象
        ListOperations<String, String> opsForList = redisTemplate.opsForList();
        //从右边存进去
        opsForList.rightPush(HotArticleConstants.HOT_ARTICLE_SCORE_BEHAVIOR_LIST,behaviorMess);

        log.info(" 文章实时更新队列: 接收到文章行为变化 消息内容: {}",behaviorMess);

    }
}
